<?php
namespace app\jobmanagement\service;

use app\constdir\ApiConst;
use think\Exception;
use app\model\Product as mProduct;
use app\model\ProductWork as mProductWork;
use app\model\TaskTask as mTaskTask;
use app\model\ProductLadder as mProductLadder;
use app\model\ProductLadderItem as mProductLadderItem;

/**
 * Class Product
 * @package app\jobmanagement\service
 */
class Product
{
    private $mProduct;
    private $mProductWork;
    private $mTaskTask;
    private $mProductLadder;
    private $mProductLadderItem;
    private $cProdUnit;
    private $dd_user_id;
    private $dept_id;
    public function __construct(){
        $this->mProduct = new mProduct();
        $this->mProductWork = new mProductWork();
        $this->mTaskTask = new mTaskTask();
        $this->mProductLadder = new mProductLadder();
        $this->mProductLadderItem = new mProductLadderItem();
        $unit = [];
        foreach (config('dic.prod_unit') as $key => $value){
            $unit[$key]['id'] =  $key;
            $unit[$key]['name'] = $value;
        }
        $this->cProdUnit = $unit;
        $this->dd_user_id = session('dd_user_id');
        $this->dept_id = session('dept_id');
    }


    /**
     * @introduction:产品的添加修改以及工种的变更修改
     * @param $param
     * @return bool|string
     * @throws \think\exception\PDOException
     * @author:cxh
     * @date: 2020/5/20 11:00
     */
    public function productSave($param){
        //启动事务
        $this->mProduct->startTrans();
        try {
            $date_time = date("Y-m-d H:i:s",time());
            $user = $this->dd_user_id;
            switch ($param['type']){
                case 1:
                    //当新增时如果有产品ID表示错误
                    if(!empty($param['id'])){
                        return ['code'=> ApiConst::PRODUCT_ADD_PROD_ID_ERROR_CODE, 'msg'=>ApiConst::PRODUCT_ADD_PROD_ID_ERROR_MSG];
                    }
                    $data = [
                        'name' => $param['name'],
                        'amount' => $param['amount'],
                        'unit' => $param['unit'],
                        'dept_id' => $this->dept_id,
                        'create_time' => $date_time,
                        'create_user' => $user,
                        'update_time' => $date_time,
                        'update_user' => $user,
                    ];
                    $prod_id = $this->mProduct
                        ->insertGetId($data);
                    if(empty($prod_id)){
                        return ['code'=> ApiConst::PRODUCT_ADD_RETURN_ID_ERROR_CODE, 'msg'=>ApiConst::PRODUCT_ADD_RETURN_ID_ERROR_MSG];
                    }
                    //获取新增的产品ID从而进行工种的添加
                    $prod_work = $this->productWorkSave($param['work'],$prod_id);
                    if(is_array($prod_work)){
                        return $prod_work;
                    }
                    break;

                case 2:
                    //当编辑时如果没有产品ID表示错误
                    if(empty($param['id'])){
                        return ['code'=> ApiConst::PRODUCT_EDIT_PROD_ID_ERROR_CODE, 'msg'=>ApiConst::PRODUCT_EDIT_PROD_ID_ERROR_MSG];
                    }
                    $data_up = [
                        'name' => $param['name'],
                        'amount' => $param['amount'],
                        'unit' => $param['unit'],
                        'update_time' => $date_time,
                        'update_user' => $user,
                    ];
                    $prod_id = $this->mProduct
                        ->where('id',$param['id'])
                        ->update($data_up);

                    //根据修改的ID进行工种的操作
                    $prod_work = $this->productWorkSave($param['work'],$param['id']);
                    if(is_array($prod_work)){
                        return $prod_work;
                    }
                    break;
            }
            //提交事务
            $this->mProduct->commit();
        }catch (\Exception $e){
            //事务回滚
            $this->mProduct->rollback();
            return ['code'=> ApiConst::FAILED_CODE, 'msg'=> $e->getMessage()];
        }

        return true;

    }


    /**
     * @introduction:通过传入的JSON数据进行产品工种的处理
     * @param $param
     * @param $prod_id
     * @return bool|string|null
     * @author:cxh
     * @date: 2020/5/20 10:25
     */
    public function productWorkSave($param,$prod_id){

        $workList = json_decode($param,true);

        if(empty($workList) or empty($prod_id)){
            return ['code'=> ApiConst::PRODUCT_WORK_ADD_ERROR_CODE, 'msg'=>ApiConst::PRODUCT_WORK_ADD_ERROR_MSG];
        }
        $idAll = null;

        foreach ($workList as $value){
            switch ($value['type']){
                case 1 : //新增
                    if(!empty($value['id'])){
                        return ['code'=> ApiConst::PRODUCT_WORK_ADD_ID_ERROR_CODE, 'msg'=>ApiConst::PRODUCT_WORK_ADD_ID_ERROR_MSG];
                    }
                    $addWork = $this->mProductWork
                        ->insertGetId(['name'=>$value['name'],'prod_id'=>$prod_id]);
                    $idAll .= $addWork.',';
                    break;
                case 2: //编辑
                    if(empty($value['id'])){
                        return ['code'=> ApiConst::PRODUCT_WORK_EDIT_ID_ERROR_CODE, 'msg'=>ApiConst::PRODUCT_WORK_EDIT_ID_ERROR_MSG];
                    }
                    $updateWork = $this->mProductWork
                        ->where(['id'=>$value['id'],'prod_id'=>$prod_id])
                        ->update(['name' => $value['name'],'prod_id'=>$prod_id]);
                    $idAll .= $value['id'].',';
                    break;
                case 3: //删除
                    if(empty($value['id'])){
                        return ['code'=> ApiConst::PRODUCT_WORK_DELETE_ID_ERROR_CODE, 'msg'=>ApiConst::PRODUCT_WORK_DELETE_ID_ERROR_MSG];
                    }
                    $deleteWork = $this->mProductWork
                        ->where(['id'=>$value['id'],'prod_id'=>$prod_id])
                        ->delete();
                    break;
            }

        }

        return !empty($idAll) ? rtrim($idAll,',') : null;

    }


    /**
     * @introduction:产品新增或者编辑所需内容视图页输出
     * @param $param
     * @return array|bool|false|\PDOStatement|string|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @author:cxh
     * @date: 2020/5/20 14:48
     */
    public function productEdit($param){
        //根据type来判定是编辑还是新增

        $data = [];
        $work_list = [];
        if($param['type'] == 2){
            $data = $this->mProduct
                ->field('id,name,amount,unit')
                ->where('id',$param['id'])
                //->where('create_user',$this->dd_user_id)
                ->find();
            if(empty($data)){
                return ['code'=> ApiConst::PRODUCT_INFO_ERROR_CODE, 'msg'=>ApiConst::PRODUCT_INFO_ERROR_MSG];
            }

            $data['unit_cn'] = !empty($this->cProdUnit[$data['unit']]['name']) ? $this->cProdUnit[$data['unit']]['name'] : null;
            $work_list = $this->mProductWork
                ->where('prod_id',$param['id'])
                ->select();
        }

        //单位列表
        if(!empty($work_list)){
            $data['work_list'] = $work_list;
        }
        $data['unit_list'] = $this->cProdUnit;

        return $data;
    }


    /**
     * @introduction:根据分页获取对应用户的产品列表
     * @param $param
     * @return bool|false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @author:cxh
     * @date: 2020/5/20 16:12
     */
    public function productList($param){

        $page_num = PAGE_SIZE;
        $page = ($param['page'] - 1) * $page_num;
        $add_where = ['dept_id' => $this->dept_id];
        $prod_list = $this->mProduct
            //->where('create_user',$this->dd_user_id)
            ->where($add_where)
            ->limit($page,$page_num)
            ->order('id desc')
            ->select();
        foreach ($prod_list as $key => $value){
           $prod_list[$key]['unit_cn'] =  !empty($this->cProdUnit[$value['unit']]['name']) ? $this->cProdUnit[$value['unit']]['name'] : null;
        }
        return $prod_list;
    }


    /**
     * @introduction:根据产品ID查询出详细信息以及工种信息
     * @param $param
     * @return array|bool|false|\PDOStatement|string|\think\Model
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @author:cxh
     * @date: 2020/5/20 16:27
     */
    public function productInfo($param){

        $data = $this->mProduct
                ->field('id,name,amount,unit')
                ->where('id',$param['id'])
                //->where('create_user',$this->dd_user_id)
                ->find();

        if(empty($data)){
            return ['code'=> ApiConst::PRODUCT_INFO_ERROR_CODE, 'msg'=>ApiConst::PRODUCT_INFO_ERROR_MSG];
        }
        $data['unit_cn'] = !empty($this->cProdUnit[$data['unit']]['name']) ? $this->cProdUnit[$data['unit']]['name'] : null;
        $work_list = $this->mProductWork
                ->where('prod_id',$param['id'])
                ->select();

        if(!empty($work_list)){
            $data['work_list'] = $work_list;
        }
        return $data;

    }


    /**
     * @introduction:根据参数产品ID去删除对应的产品
     * @param $param
     * @return array|bool
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @author:cxh
     * @date: 2020/5/23 16:37
     */
    public function productDelete($param){
        //查询该产品下面是否存在任务单
        $task = $this->mTaskTask
            ->where('prod_id',$param['id'])
            ->find();
        if(!empty($task)){
            return ['code'=> ApiConst::PRODUCT_DELETE_TASK_ERROR_CODE, 'msg'=>ApiConst::PRODUCT_DELETE_TASK_ERROR_MSG];
        }
        //启动事务
        $this->mProduct->startTrans();
        try {
            //删除产品
            $data = $this->mProduct
                ->where('id',$param['id'])
                //->where('create_user',$this->dd_user_id)
                ->delete();
            //删除产品下面工种
            $data = $this->mProductWork
                ->where('prod_id',$param['id'])
                //->where('create_user',$this->dd_user_id)
                ->delete();
            //删除产品下面阶梯配置
            $data = $this->mProductLadder
                ->where('prod_id',$param['id'])
                ->delete();
            //删除产品下面阶梯配置详细列表
            $data = $this->mProductLadderItem
                ->where('prod_id',$param['id'])
                ->delete();
            //提交事务
            $this->mProduct->commit();
            return true;
        }catch (Exception $e){
            //回滚事务
            $this->mProduct->rollback();
            return ['code'=> ApiConst::PRODUCT_DELETE_PRODUCT_ERROR_CODE, 'msg'=>ApiConst::PRODUCT_DELETE_PRODUCT_MSG];
        }



    }


    /**
     * @introduction:产品阶梯配置相关数据保存以及配置列表增加
     * @param $param
     * @return array|bool
     * @throws \think\exception\PDOException
     * @author:cxh
     * @date: 2020/7/29 16:25
     */
    public function saveProductLadder($param){
        //启动事务
        $this->mProductLadder->startTrans();
        try {
            $date_time = date("Y-m-d H:i:s");
            $user = $this->dd_user_id;
            switch ($param['type']){
                case 1:
                    $data = [
                        'name' => $param['name'],
                        'prod_id' => $param['prod_id'],
                        'add_time' => $date_time,
                        'add_user' => $user,
                        'status' => 2,
                        'dept_id' => $this->dept_id,
                        'ladder_status' => 1,
                        'remark' => $param['remark'],
                        'status_remark' => get_user_name($user).'于'.$date_time.'添加了阶梯配置;',
                    ];
                    $ladder_id = $this->mProductLadder
                        ->insertGetId($data);
                    if(empty($ladder_id)){
                        return ['code'=> ApiConst::PRODUCT_ADD_LADDER_ID_ERROR_CODE, 'msg'=>ApiConst::PRODUCT_ADD_LADDER_ID_ERROR_MSG];
                    }
                    //获取新增的ID从而进行列表的添加
                    $ladder_list = $this->productLadderListSave($param['list'],$param['prod_id'],$ladder_id);
                    if(is_array($ladder_list)){
                        return $ladder_list;
                    }
                    break;

                case 2:
                    //查询出详细信息
                    $ladder_info = $this->productLadderInfo($param['id']);
                    $data = [
                        'name' => $param['name'],
                        'prod_id' => $param['prod_id'],
                        'status' => 2,
                        'ladder_status' => 1,
                        'remark' => $param['remark'],
                        'status_remark' => $ladder_info['status_remark'].get_user_name($user).'于'.$date_time.'修改了阶梯配置;',
                    ];
                    $ladder_id = $this->mProductLadder
                        ->where('id',$param['id'])
                        ->update($data);

                    //根据修改的ID进行配置列表的操作
                    $ladder_list = $this->productLadderListSave($param['list'],$param['prod_id'],$param['id']);
                    if(is_array($ladder_list)){
                        return $ladder_list;
                    }
                    //删除传参过来的数据（移除初定的type=3情况进行删除的模式，改变为删除那些数据进行传ID过来进行删除以逗号隔开形式）
                    if(!empty($param['arr_ladder'])){
                        $deleteLadder = $this->mProductLadderItem
                            ->where(['id'=>['in',$param['arr_ladder']],'ladder_id'=>$param['id']])
                            ->delete();
                        if(empty($deleteLadder)){
                            return ['code'=> ApiConst::PRODUCT_DELETE_PRODUCT_ERROR_CODE, 'msg'=>ApiConst::PRODUCT_DELETE_PRODUCT_MSG];
                        }
                    }

                    break;
            }
            //提交事务
            $this->mProductLadder->commit();
        }catch (\Exception $e){
            //事务回滚
            $this->mProductLadder->rollback();
            return ['code'=> ApiConst::FAILED_CODE, 'msg'=> $e->getMessage()];
        }

        return true;

    }


    /**
     * @introduction:通过传入json数据以及相应ID保存阶梯配置列表信息
     * @param $param
     * @param $prod_id
     * @param $ladder_id
     * @return array|string|null
     * @author:cxh
     * @date: 2020/7/29 16:12
     */
    public function productLadderListSave($param,$prod_id,$ladder_id){

        $ladderList = json_decode($param,true);

        if(empty($ladderList) or empty($prod_id) or empty($ladder_id)){
            return ['code'=> ApiConst::PRODUCT_LADDER_ADD_ERROR_CODE, 'msg'=>ApiConst::PRODUCT_LADDER_ADD_ERROR_MSG];
        }
        $idAll = null;
        $pre_num_max = 0;
        foreach ($ladderList as $key => $value){
            if((float)$value['price'] <= 0){
                return ['code'=> ApiConst::PRODUCT_LADDER_NULL_ERROR_CODE, 'msg'=>ApiConst::PRODUCT_LADDER_NULL_ERROR_MSG];
            }
            $num_min = $value['num_min'];
            $num_max = $value['num_max'];
            if (!(is_int($num_min) && is_int($num_max))){
                return ['code'=> ApiConst::PRODUCT_LADDER_INT_ERROR_CODE, 'msg'=>ApiConst::PRODUCT_LADDER_INT_ERROR_MSG];
            }
            if ($num_min < 0 || ($num_min >= $num_max)) {
                return ['code'=> ApiConst::PRODUCT_LADDER_MIN_MAX_ERROR_CODE, 'msg'=>ApiConst::PRODUCT_LADDER_MIN_MAX_ERROR_MSG];
            }
            if (($key > 0) && ($pre_num_max != ($num_min - 1))) {
                return ['code'=> ApiConst::PRODUCT_LADDER_MIN_MAX_ERROR_CODE, 'msg'=>ApiConst::PRODUCT_LADDER_MIN_MAX_ERROR_MSG];
            }
            $pre_num_max = $num_max;

            switch ($value['type']){
                case 1 : //新增
                    if(!empty($value['id'])){
                        return ['code'=> ApiConst::PRODUCT_ADD_TYPE_ID_ERROR_CODE, 'msg'=>ApiConst::PRODUCT_ADD_TYPE_ID_ERROR_MSG];
                    }
                    $data = [
                      'prod_id' => $prod_id,
                      'ladder_id' => $ladder_id,
                      'num_max' => $value['num_max'],
                      'num_min' => $value['num_min'],
                      'price' => $value['price'],
                    ];
                    $addLadder = $this->mProductLadderItem
                        ->insertGetId($data);
                    if(empty($addLadder)){
                        return ['code'=> ApiConst::FAILED_CODE, 'msg'=>ApiConst::BASE_ERROR_MSG];
                    }
                    $idAll .= $addLadder.',';
                    break;
                case 2: //编辑
                    if(empty($value['id'])){
                        return ['code'=> ApiConst::PRODUCT_EDIT_TYPE_ID_ERROR_CODE, 'msg'=>ApiConst::PRODUCT_EDIT_TYPE_ID_ERROR_MSG];
                    }
                    $data = [
                        'prod_id' => $prod_id,
                        'ladder_id' => $ladder_id,
                        'num_max' => $value['num_max'],
                        'num_min' => $value['num_min'],
                        'price' => $value['price'],
                    ];
                    $updateLadder = $this->mProductLadderItem
                        ->where(['id'=>$value['id'],'ladder_id'=>$ladder_id])
                        ->update($data);
                    $idAll .= $value['id'].',';
                    break;
                case 3: //删除
                    if(empty($value['id'])){
                        return ['code'=> ApiConst::PRODUCT_WORK_DELETE_ID_ERROR_CODE, 'msg'=>ApiConst::PRODUCT_WORK_DELETE_ID_ERROR_MSG];
                    }
                    $deleteLadder = $this->mProductLadderItem
                        ->where(['id'=>$value['id'],'ladder_id'=>$ladder_id])
                        ->delete();
                    break;
            }

        }

        return !empty($idAll) ? rtrim($idAll,',') : null;

    }


    /**
     * @introduction:根据阶梯ID查询阶梯详情
     * @param $param
     * @return array|bool|false|\PDOStatement|string|\think\Model
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @author:cxh
     * @date: 2020/7/29 17:22
     */
    public function productLadderInfo($id){

        $data = $this->mProductLadder
            ->field('id,name,prod_id,status,ladder_status,remark,status_remark')
            ->where('id',$id)
            ->find();

        if(empty($data)){
            return ['code'=> ApiConst::PRODUCT_INFO_ERROR_CODE, 'msg'=>ApiConst::PRODUCT_INFO_ERROR_MSG];
        }
        $data['status_cn'] =  !empty(config('dic.ladder_status')[$data['status']]) ? config('dic.ladder_status')[$data['status']] : null;
        $data['ladder_status_cn'] =  !empty(config('dic.ladder_ladder_status')[$data['ladder_status']]) ? config('dic.ladder_ladder_status')[$data['ladder_status']] : null;

        return $data;

    }


    /**
     * @introduction:根据阶梯配置ID查询属于它的所有配置列表
     * @param $ladder_id
     * @return bool|false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @author:cxh
     * @date: 2020/7/29 17:21
     */
    public function productLadderInfoList($ladder_id){

        $ladder_info_list = $this->mProductLadderItem
            ->where('ladder_id',$ladder_id)
            ->select();

        return $ladder_info_list;

    }


    /**
     * @introduction:获取阶梯计费配置列表数据输送
     * @param $param
     * @return bool|false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @author:cxh
     * @date: 2020/7/30 11:43
     */
    public function productLadderList($param){

        $page_num = PAGE_SIZE;
        $page = ($param['page'] - 1) * $page_num;
        $add_where = ['prod_id' => $param['prod_id']];
        $ladder_list = $this->mProductLadder
            ->field('id,name,prod_id,status,ladder_status,add_time,remark')
            ->where($add_where)
            ->limit($page,$page_num)
            ->order('id desc')
            ->select();
        foreach ($ladder_list as $key => $value){
            $ladder_list[$key]['status_cn'] =  !empty(config('dic.ladder_status')[$value['status']]) ? config('dic.ladder_status')[$value['status']] : null;
            $ladder_list[$key]['ladder_status_cn'] =  !empty(config('dic.ladder_ladder_status')[$value['ladder_status']]) ? config('dic.ladder_ladder_status')[$value['ladder_status']] : null;
        }
        return $ladder_list;
    }


    /**
     * @introduction:删除阶梯配置相关信息以及下面列表
     * @param $param
     * @return array|bool
     * @throws \think\exception\PDOException
     * @author:cxh
     * @date: 2020/7/30 11:49
     */
    public function productLadderDelete($param){
        //启动事务
        $this->mProductLadder->startTrans();
        try {
            //删除
            $data = $this->mProductLadder
                ->where('id',$param['id'])
                ->delete();
            //删除下面
            $data = $this->mProductLadderItem
                ->where('ladder_id',$param['id'])
                ->delete();
            //提交事务
            $this->mProductLadder->commit();
            return true;
        }catch (Exception $e){
            //回滚事务
            $this->mProductLadder->rollback();
            return ['code'=> ApiConst::PRODUCT_DELETE_PRODUCT_ERROR_CODE, 'msg'=>ApiConst::PRODUCT_DELETE_PRODUCT_MSG];
        }



    }


    /**
     * @introduction:新增阶梯审核列表展示加入产品信息
     * @param $param
     * @return bool|false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @author:cxh
     * @date: 2020/7/30 16:41
     */
    public function productLadderCheckList($param){

        $page_num = PAGE_SIZE;
        $page = ($param['page'] - 1) * $page_num;
        $add_where = ['status' => 2 , 'ladder_status' => 1 ,'dept_id' => $this->dept_id];
        $ladder_list = $this->mProductLadder
            ->field('id,name,prod_id,status,ladder_status,add_time,remark')
            ->where($add_where)
            ->limit($page,$page_num)
            ->order('id desc')
            ->select();
        foreach ($ladder_list as $key => $value){

            $prodInfo = $this->productInfo(['id'=>$value['prod_id']]);
            $ladder_list[$key]['prod_name'] = $prodInfo['name'];
            $ladder_list[$key]['prod_amount'] = $prodInfo['amount'];
            $ladder_list[$key]['prod_unit_cn'] = $prodInfo['unit_cn'];
            $ladder_list[$key]['list'] = $this->productLadderInfoList($value['id']);

            $ladder_list[$key]['status_cn'] =  !empty(config('dic.ladder_status')[$value['status']]) ? config('dic.ladder_status')[$value['status']] : null;
            $ladder_list[$key]['ladder_status_cn'] =  !empty(config('dic.ladder_ladder_status')[$value['ladder_status']]) ? config('dic.ladder_ladder_status')[$value['ladder_status']] : null;
        }
        return $ladder_list;
    }


    /**
     * @introduction:审核或者拒绝阶梯配置信息
     * @param $param
     * @return array|bool
     * @throws \think\exception\PDOException
     * @author:cxh
     * @date: 2020/7/30 16:48
     */
    public function productLadderCheck($param){
        //启动事务
        $this->mProductLadder->startTrans();
        try {
            $date_time = date("Y-m-d H:i:s");
            $user = $this->dd_user_id;
            //查询出详细信息
            $ladder_info = $this->productLadderInfo($param['id']);
            switch ($param['type']){
                case 1:
                    $data = [
                        'audit_time' => $date_time,
                        'audit_user' => $user,
                        'status' => 1,
                        'ladder_status' => 2,
                        'status_remark' => $ladder_info['status_remark'].get_user_name($user).'于'.$date_time.'审核通过了阶梯配置;',
                    ];
                    $ladder_id = $this->mProductLadder
                        ->where('id',$param['id'])
                        ->update($data);
                    break;

                case 2:
                    $data = [
                        'audit_time' => $date_time,
                        'audit_user' => $user,
                        'status' => 2,
                        'ladder_status' => 3,
                        'status_remark' => $ladder_info['status_remark'].get_user_name($user).'于'.$date_time.'拒绝审核了阶梯配置;',
                    ];
                    $ladder_id = $this->mProductLadder
                        ->where('id',$param['id'])
                        ->update($data);
                    break;
            }
            //提交事务
            $this->mProductLadder->commit();
        }catch (\Exception $e){
            //事务回滚
            $this->mProductLadder->rollback();
            return ['code'=> ApiConst::FAILED_CODE, 'msg'=> $e->getMessage()];
        }

        return true;

    }



}




























